﻿using System;
using System.Threading;

namespace UniRx
{
	// Token: 0x02000202 RID: 514
	public sealed class ScheduledDisposable : ICancelable, IDisposable
	{
		// Token: 0x06000C37 RID: 3127 RVA: 0x0003CC80 File Offset: 0x0003B080
		public ScheduledDisposable(IScheduler scheduler, IDisposable disposable)
		{
			this.scheduler = scheduler;
			this.disposable = disposable;
		}

		// Token: 0x170000DE RID: 222
		// (get) Token: 0x06000C38 RID: 3128 RVA: 0x0003CC98 File Offset: 0x0003B098
		public IScheduler Scheduler
		{
			get
			{
				return this.scheduler;
			}
		}

		// Token: 0x170000DF RID: 223
		// (get) Token: 0x06000C39 RID: 3129 RVA: 0x0003CCA0 File Offset: 0x0003B0A0
		public IDisposable Disposable
		{
			get
			{
				return this.disposable;
			}
		}

		// Token: 0x170000E0 RID: 224
		// (get) Token: 0x06000C3A RID: 3130 RVA: 0x0003CCAA File Offset: 0x0003B0AA
		public bool IsDisposed
		{
			get
			{
				return this.isDisposed != 0;
			}
		}

		// Token: 0x06000C3B RID: 3131 RVA: 0x0003CCB8 File Offset: 0x0003B0B8
		public void Dispose()
		{
			this.Scheduler.Schedule(new Action(this.DisposeInner));
		}

		// Token: 0x06000C3C RID: 3132 RVA: 0x0003CCD2 File Offset: 0x0003B0D2
		private void DisposeInner()
		{
			if (Interlocked.Increment(ref this.isDisposed) == 1)
			{
				this.disposable.Dispose();
			}
		}

		// Token: 0x04000703 RID: 1795
		private readonly IScheduler scheduler;

		// Token: 0x04000704 RID: 1796
		private volatile IDisposable disposable;

		// Token: 0x04000705 RID: 1797
		private int isDisposed;
	}
}
